package ts.test.shizahn.shizhan3;

import net.sf.cglib.proxy.Enhancer;

public class IntermdiaryCglibProxyFactory {
    private static IntermediaryMethodInterceptor callback = new IntermediaryMethodInterceptor();

    /**
     * 工厂方法
     */
    public static <T> T create(Class<T> target){
        Enhancer  enhancer = new Enhancer();
        //为重写的方法添加回调
        enhancer.setCallback(callback);
        enhancer.setSuperclass(target); //设置父类
        return (T) enhancer.create();   //创建代理对象
    }
}
